package control;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.ControlDB;

@WebServlet("/ReturnArticle")	// 映射浏览器访问url为ReturnArticle
public class ReturnArticle extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setContentType("text/plain;charset=utf-8");
		
		String requestId = req.getParameter("id");
		
		if (requestId != null) {
			int id = Integer.parseInt(requestId);

			ControlDB ctrl = new ControlDB();
			
			PrintWriter out = resp.getWriter();
			out.print(ctrl.article(id));
			out.close();
		} else {
			PrintWriter outTitle = resp.getWriter();
			outTitle.print(false);
			outTitle.close();
		}
		
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}
